/**
 * @file PAT.h
 *
 * This file implements the PAT parsing.
 *
 * @author Luc Fourestier
 * @date 2009
 */

#ifndef PAT_H_
#define PAT_H_

#include <stdio.h>


// Errors
#define PAT_ERROR_NOT_A_PAT 1

#define PAT_PID 0
#define PAT_TID 0

#define PAT_MAX_PROGRAM_DESC 10

/**
 * The program number and PID
 */
typedef struct PAT_ProgramDesc_s
{
	unsigned short program_number;
	unsigned short PID;
}PAT_ProgramDesc_t;

/**
 * The PAT
 */
typedef struct PAT_s
{
	unsigned char table_id;
	unsigned char section_syntax_indicator;
	unsigned char zero;
	unsigned char reserved_1;
	unsigned short section_length;
	unsigned short transport_stream_id;
	unsigned char reserved_2;
	unsigned char version_number;
	unsigned char current_next_indicator;
	unsigned char section_number;
	unsigned char last_section_number;

	unsigned int ProgramDescNumber;
	PAT_ProgramDesc_t program_descriptors[PAT_MAX_PROGRAM_DESC];

	unsigned int CRC_32;
}PAT_t;

/**
 * @brief Fill the PAT
 */
int PAT_Create(unsigned char * Buffer, unsigned int *Size, PAT_t * PAT);

/**
 * @brief Print the PAT
 */
int PAT_Print(PAT_t * PAT, char * Name, int level, FILE * Output);

/**
 * @brief Check the PAT validity
 */
int PAT_CheckPAT(unsigned char * Buffer, unsigned int Size);

/**
 * @brief Get the TSID
 */
int PAT_GetTSID(unsigned char * Buffer, unsigned int Size, unsigned short *TSID);

#endif /* PAT_H_ */
